package cn.wf.order.controller;

import cn.wf.order.dto.OrderDTO;
import cn.wf.order.message.StreamClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.binding.BinderAwareChannelResolver;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description
 * @Author 万飞
 * @Date 2018/8/12 2:27
 */
@RestController
public class SendMessageController {

    @Autowired
    private BinderAwareChannelResolver resolver;  //固定使用这个

    @GetMapping("sendMessage")
    public void process() {
        String message = "now:" + new Date();
        //发送消息
        resolver.resolveDestination(StreamClient.INPUT).send(MessageBuilder.withPayload(message).build());
    }

    /**
     * 发送 orderDTO对象
     */
    @GetMapping("sendMessageOrderDTO")
    public void processOrderDTO() {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setOrderId("123123");
        resolver.resolveDestination(StreamClient.INPUT).send(MessageBuilder.withPayload(orderDTO).build());
    }
}
